package JZOffer;

// 和为s的两个数字
public class JzOffer57 {
    public int[] twoSum(int[] nums, int target) {
        int l = 0;
        int r = nums.length-1;

        while (l < r) {
            if (nums[l] + nums[r] > target) {
                r--;
            }
            if (nums[l] + nums[r] < target) {
                l++;
            }
            if (nums[l] + nums[r] == target) {
                return new int[] {nums[l], nums[r]};
            }
        }
        return new int[] {0};
    }
}
